fix: exclude VASP data generator from pytest - #387
Conversation
|
Warning Review limit reachedNext included review available in 59 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #387 +/- ##
=======================================
Coverage 84.43% 84.43%
=======================================
Files 104 104
Lines 6110 6110
=======================================
Hits 5159 5159
Misses 951 951 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Rename the fixture generator outside pytest patterns and guard generation behind an explicit main entry point. Closes deepmodeling#361 Coding-Agent: Codex Codex-Version: codex-cli 0.149.1 Model: gpt-5.6-sol Reasoning-Effort: xhigh
d3e0f9f to
9e16f04
Compare
Retracted: submitted without the maintainer's decision. Will re-review and let the maintainer choose the action.
wanghan-iapcm
left a comment
There was a problem hiding this comment.
The rename is right and I verified it fixes a real failure. Blocking only on the docstrings, which now advertise a regeneration workflow that corrupts the fixtures.
The fix works
With the old filename restored, pytest --collect-only -q tests/fp/data.vasp.kp.gf gives
ERROR tests/fp/data.vasp.kp.gf/make_kp_test.py - FileNotFoundError: [Errno 2] No such file or directory: 'POSCAR'
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
At this head it reports "no tests collected", clean. The repository configures no python_files, so pytest's default ["test_*.py", "*_test.py"] applies and the old name matched the second pattern. Nothing anywhere in the tree references the generator by either name, so the rename breaks nothing.
Two corrections to the record while I am here, neither of which changes the verdict on the rename.
The AttributeError: module 'ase' has no attribute 'geometry' quoted in #361 does not actually fire. A bare import ase really does hide ase.geometry in ase 3.28, but import dpdata binds it as a side effect, and the old file imported dpdata. With the old import order the attribute access succeeds, which is why the collection error above is a FileNotFoundError raised on the line after cellpar_to_cell. Importing the function directly is still worth doing, since relying on a third-party package's import graph is fragile, but it is hardening rather than a fix for an observed error.
And the blast radius is smaller than the issue suggests: CI runs coverage run ... -m unittest, whose default discovery pattern test*.py never matched this file. This is a local-developer fix. Note that #388 does not change that either, it only declares the dependency.
Blocking: main() regenerates half of each fixture
The PR adds a module docstring saying the script regenerates the k-point test data, a main() documented as regenerating all fixture directories, and a __main__ guard. Together these turn a script that previously only ran by accident into one a maintainer is invited to run. But make_one writes only POSCAR. Each test.NNN/ also holds a kp.ref, which tests/fp/test_vasp.py loads and compares against; nothing in the repository writes those.
So following the new docstring desynchronizes the two halves:
$ cd tests/fp/data.vasp.kp.gf && python make_kp_data.py # exit 0, all 30 POSCARs replaced
$ pytest tests/fp/test_vasp.py -k make_kp
FAILED tests/fp/test_vasp.py::TestVASPInputs::test_make_kp - AssertionError: False is not true
Recomputing make_kspacing_kpoints(cell, 0.16, False) for each directory afterwards, all 30 disagree with their committed kp.ref.
Either is fine by me: have make_one also write kp.ref alongside the POSCAR, or reword the docstrings so they do not promise a complete regeneration and say the references must be redone by hand. What should not ship is a documented entry point that quietly breaks the suite.
Not blocking
make_one reads a bare "POSCAR" and main writes bare test.NNN/, so the new entry point only works when the current directory is exactly the fixture directory; from the repository root it exits 1 with the same FileNotFoundError that caused the original bug. Anchoring both to Path(__file__).parent would make the __main__ guard robust rather than merely lucky, and the file is already open.
Separately, and definitely not for this PR: the angle sampling has been wrong since the file was created in 2022. # [1, 179) sits above np.random.random(3) * (178 / 180) + 1, which yields angles in [1, 1.99) degrees, so every fixture is a nearly collinear cell. Measured across the 30 committed POSCARs, all 90 angles fall between 1.0007 and 1.9848 degrees, and test.000/kp.ref is 3012 1844 2485. The test therefore never exercises ordinary cells. I mention it because you are rewriting this file, but if anyone picks it up: the obvious correction * 178 + 1 is not safe. Uniformly random angle triples are usually not realizable as a parallelepiped, and 143 of 200 sampled triples tripped ase's cz_sqr >= 0 assertion. It needs rejection sampling, and regenerating kp.ref along with it.
On merge order: this conflicts with #405, which modifies make_kp_test.py while this PR deletes it (CONFLICT (modify/delete)). #382, #383, #384 and #386 all merge clean.
|
|
||
|
|
||
| def main(ntest=30): | ||
| """Regenerate all randomized fixture directories.""" |
There was a problem hiding this comment.
This docstring, and the module one on line 2, promise a regeneration this function does not perform. make_one writes only POSCAR, but each test.NNN/ directory also contains a kp.ref that tests/fp/test_vasp.py compares computed k-points against, and nothing in the repository writes those.
Running exactly what the docstrings advertise:
$ cd tests/fp/data.vasp.kp.gf && python make_kp_data.py # exit 0
$ pytest tests/fp/test_vasp.py -k make_kp
FAILED tests/fp/test_vasp.py::TestVASPInputs::test_make_kp - AssertionError: False is not true
and recomputing afterwards, all 30 directories disagree with their committed kp.ref.
Before this PR the loop only ran by accident at import time, so this was a latent hazard. Adding main(), the __main__ guard and these docstrings makes it an invitation. Either write kp.ref here too (make_kspacing_kpoints(cell, 0.16, False)), or say in the docstring that the references are not regenerated and must be redone by hand.
| # [1, 179) | ||
| [alpha, beta, gamma] = np.random.random(3) * (178 / 180) + 1 | ||
| cell = cellpar_to_cell([aa, bb, cc, alpha, beta, gamma]) | ||
| system = dpdata.System("POSCAR") |
There was a problem hiding this comment.
Not blocking, but worth fixing while the file is open: this reads a bare relative "POSCAR", and main writes bare relative test.NNN/ directories, so the newly advertised entry point only works when the current directory is exactly tests/fp/data.vasp.kp.gf. From the repository root it exits 1 with FileNotFoundError: 'POSCAR' -- the same error that made pytest collection fail in the first place, since pytest imports collected modules with the working directory at the rootdir.
Anchoring both paths to Path(__file__).parent makes the __main__ guard robust instead of dependent on where it is invoked from.
| # [0.5, 1) | ||
| [aa, bb, cc] = np.random.random(3) * 0.5 + 0.5 | ||
| # [1, 179) | ||
| [alpha, beta, gamma] = np.random.random(3) * (178 / 180) + 1 |
There was a problem hiding this comment.
Carried over unchanged from the old file, so not something this PR introduced, and I am not asking for it here. Recording it because the file is being rewritten and the comment is false.
178 / 180 is about 0.9889, so this yields angles in [1, 1.99) degrees, not [1, 179). cellpar_to_cell takes degrees, so every generated cell is nearly collinear. I measured all 90 angles across the 30 committed fixtures: 1.0007 to 1.9848 degrees. That is also why test.000/kp.ref reads 3012 1844 2485 -- k-point counts in the thousands only happen for cells this flat at kspacing 0.16. So test_make_kp has effectively no coverage of the ordinary-cell regime.
If anyone fixes this: * 178 + 1 is not the answer. Uniformly random angle triples are usually not geometrically realizable, and 143 of 200 samples I tried raised ase's cz_sqr >= 0 assertion. It needs rejection sampling, plus regenerating kp.ref.
Summary
main()functioncellpar_to_celldirectly instead of relying onase.geometryas a module attributeTests
pytest --collect-only -q tests/fp/data.vasp.kp.gf(no tests collected, no import-time failure)ruff format --check tests/fp/data.vasp.kp.gf/make_kp_data.pyisort --check-only tests/fp/data.vasp.kp.gf/make_kp_data.pygit diff --checkCloses #361
Coding agent: Codex
Codex version: codex-cli 0.149.0
Model: gpt-5.6-sol
Reasoning effort: xhigh